MAX = 100000

pentagonals = set([n*(3*n-1)/2  for n in range(165, MAX)])
hexagonals = set([n*(2*n-1) for n in range(143, MAX)])

for n in range(286, MAX):
    tri = n*(n+1)/2
    if tri in pentagonals and tri in hexagonals:
        print tri
        break
